<?php 
    App::import('Model', 'PacientesSeguro'); 
    $modeloPacientesSeguro = new PacientesSeguro();
    $idPaciente = $this->request->data['Paciente']['id'];
?>
<div class="page_title">
    <span class="title_icon"><span class="coverflow"></span></span>
    <h3>Pacientes</h3>    
</div>
<div id="content">
    <div class="grid_container">
        <div class="grid_12">
            <!--            <form action="#" method="post" id="form103" class="form_container left_label valid_tip">-->
            <?php echo $this->Form->create('Paciente', array('id' => "form103", 'class' => "form_container left_label valid_tip")) ?>
            <?php echo $this->Form->hidden('Paciente.id', array('value'=>$this->request->data['Paciente']['id']));?>
            <?php echo $this->Form->hidden('PacientesSeguro.id', array('value'=>$this->request->data['PacientesSeguro']['id']));?>
            <div class="widget_wrap">
                <div class="widget_top">
                    <span class="h_icon list"></span>
                    <h6>EDITAR PACIENTE COD: <?php echo $this->request->data['Paciente']['codigo'].' -  '.$this->request->data['Paciente']['nombres'].' '.$this->request->data['Paciente']['ap_paterno'].' '.$this->request->data['Paciente']['ap_materno']?></h6>
                </div>
                <div class="widget_content">

                    <ul>
                        <!-- <li>
                            <center><td>
                                <?php $ruta = $this->request->data['Paciente']['foto'];?>
                                <?php echo $this->Html->image("$ruta", array('width'=>180, 'height'=>150))?>
                            </td></center>            
                        </li> -->
                        <li>
                            <div class="form_grid_12">
                                <label class="field_title">Nombres completos</label>
                                <div class="form_input">
                                    <div class="form_grid_4 alpha">
                                        <?php echo $this->Form->text('nombres', array('tabindex' => 1, 'class' => 'required')) ?>
                                        <span class=" label_intro">Nombres</span>
                                    </div>
                                    <div class="form_grid_4">
                                        <?php echo $this->Form->text('ap_paterno', array('tabindex' => 1)) ?>
                                        <span class=" label_intro">Apellido paterno</span>
                                    </div>
                                    <div class="form_grid_4">
                                        <?php echo $this->Form->text('ap_materno', array('tabindex' => 1)) ?>
                                        <span class=" label_intro">Apellido materno</span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                            </div>
                        </li>
                        
                        <li>
                            <div class="form_grid_12">
                                <label class="field_title">FECHA DE NACIMIENTO Y SEXO</label>
                                <div class="form_input">
                                    <div class="form_grid_4 alpha">

                                        <?php echo $this->Form->text('fecha_nacimiento', array('id' => 'date', 'class' => 'validate', 'tabindex' => '1')) ?>
                                        <span class=" label_intro">fecha dd/mm/aaaa</span>
                                    </div>
                                    <div class="form_grid_5">
                                        <?php if ($this->request->data['Paciente']['sexo'] == 'F'): ?>

                                            <span>
                                                <input name="data[Paciente][sexo]" class="radio" type="radio" value="F" tabindex="1" checked="checked">
                                                <label class="choice">Femenino</label>
                                            </span>
                                            <span>
                                                <input name="data[Paciente][sexo]" class="radio" type="radio" value="M" tabindex="1">
                                                <label class="choice">Masculino</label>
                                            </span>

                                        <?php else: ?>
                                            <span>
                                                <input name="data[Paciente][sexo]" class="radio" type="radio" value="F" tabindex="1">
                                                <label class="choice">Femenino</label>
                                            </span>
                                            <span>
                                                <input name="data[Paciente][sexo]" class="radio" type="radio" value="M" tabindex="1" checked="checked">
                                                <label class="choice">Masculino</label>
                                            </span>

                                        <?php endif; ?>
                                        <span class=" label_intro">SEXO</span>
                                    </div>
                                    <div class="form_grid_3">
                                        <?php echo $this->Form->text('carnet', array('class' => 'validate number', 'tabindex' => '1')) ?>

                                        <span class=" label_intro">CARNET DE ID</span>
                                    </div>

                                    <span class="clear"></span>
                                </div>
                            </div>
                                                     
                        </li>
                         <li>
                            <div class="form_grid_12">
                                <label class="field_title">Lugar de nacimiento</label>
                                <div class="form_input">
                                    <div class="form_grid_4 alpha">
                                        <?php echo $this->Form->text('pais', array('tabindex'=>2))?>
                                        <label class="label_intro"><b>Area/Alcaldia</b><span style="color:red">(<b>DEPARTAMENTO</b> "solo si Nacido en Ciudad")</span></label>
                                    </div>
                                    <div class="form_grid_4">
                                        <?php echo $this->Form->text('ciudad', array('tabindex'=>2))?>
                                        <label class="label_intro"><b>Comunidad/Localidad</b><span style="color:red">(<b>PROVINCIA</b>"solo si Nacido en Ciudad")</span></label>
                                    </div>                                    
                                    <span class="clear"></span>      
                                </div>
                            </div>
                        </li>
                        <li>
                        <div class="form_grid_12">
                        <label class="field_title">Profesion o carrera</label>
                        <div class="form_input">
                            <div class="form_grid_4">
                            <?php echo $this->Form->text('profesion', array('tabindex'=>3))?>
                            </div>
                            <span class="clear"></span>
                        </div>
                        </div>
                        </li>
                        <li>
                            <div class="form_grid_12">
                                <label class="field_title">Lugar de residencia actual</label>
                                <div class="form_input">
                                    <?php if ($this->request->data['Paciente']['lugar'] == 'provincia'): ?>
                                        <span>
                                            <input name="data[Paciente][lugar]" id="lugar1" class="radio" type="radio" value="provincia" tabindex="2" checked="checked">
                                            <label class="choice">Provincia</label>
                                        </span>
                                        <span>
                                            <input name="data[Paciente][lugar]" id="lugar2" class="radio" type="radio" value="ciudad" tabindex="3">
                                            <label class="choice">Ciudad</label>
                                        </span>
                                    <?php else: ?>
                                        <span>
                                            <input name="data[Paciente][lugar]" id="lugar1" class="radio" type="radio" value="provincia" tabindex="2" >
                                            <label class="choice">Provincia</label>
                                        </span>
                                        <span>
                                            <input name="data[Paciente][lugar]" id="lugar2" class="radio" type="radio" value="ciudad" tabindex="3" checked="checked">
                                            <label class="choice">Ciudad</label>
                                        </span>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </li>


                        <li id="provincia">
                            <div class="form_grid_12 multiline" >
                                <label class="field_title"></label>
                                <div class="form_input">
                                    <div class="form_grid_6 alpha">
                                        <?php echo $this->Form->text('alcaldia', array('class' => 'validate', 'tabindex' => '4')) ?>

                                        <span class=" label_intro">Area / Alcaldia</span>
                                    </div>
                                    <div class="form_grid_6 ">
                                        <?php echo $this->Form->text('localidad', array('class' => 'validate', 'tabindex' => '4')) ?>
                                        <span class=" label_intro">Comunidad / localidad</span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                                <div class="form_input">
                                    <div class="form_grid_6 alpha">
                                        <?php echo $this->Form->text('telefono_p', array('class' => 'validate number', 'tabindex' => "4")) ?>
                                        <span class=" label_intro">Telefono </span>
                                    </div>
                                    <div class="form_grid_6 ">

                                        <?php echo $this->Form->text('celular_p', array('class' => 'validate number', 'tabindex' => "4")) ?>
                                        <span class=" label_intro">Celular </span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                                <div class="form_input">
                                    <div class="form_grid_4 alpha">
                                        <?php echo $this->Form->text('direccion_p', array('placeholder' => 'Coloque la direccion')) ?>
                                        <span class=" label_intro">DIRECCION</span>
                                    </div>
                                    <div class="form_grid_4">

                                        <select data-placeholder="Seleccione el departamento..." class="chzn-select full" name="data[Paciente][departamento_id_p]" tabindex="4" id="cb_dpto">
                                            <option value=""></option>
                                            <?php foreach ($departamentos as $departamento): ?>
                                                <?php if ($this->request->data['Paciente']['departamento_id_p'] == $departamento['Departamento']['id']): ?>
                                                    <option value="<?php echo $departamento['Departamento']['id'] ?>" selected="selected">
                                                        <?php echo $departamento['Departamento']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $departamento['Departamento']['id'] ?>">
                                                        <?php echo $departamento['Departamento']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </select>
                                        <span class=" label_intro">DEPARTAMENTO</span>
                                    </div>
                                    <div class="form_grid_4" id="cb_provincia">
                                        <select data-placeholder="Seleccione la provincia..." class="chzn-select full" name="data[Paciente][provincia_id]" tabindex="4">
                                            <option value=""></option>
                                            <?php foreach ($provincias as $provincia): ?>
                                                <?php if ($this->request->data['Paciente']['provincia_id_p'] == $provincia['Provincia']['id']): ?>
                                                    <option value="<?php echo $provincia['Provincia']['id'] ?>" selected="selected">
                                                        <?php echo $provincia['Provincia']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $provincia['Provincia']['id'] ?>">
                                                        <?php echo $provincia['Provincia']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>
                                            <?php endforeach; ?>		

                                        </select>
                                        <span class=" label_intro">PROVINCIA</span>
                                    </div>

                                    <span class="clear"></span>
                                </div>
                            </div>
                        </li>

                        <li id="departamento">
                            <div class="form_grid_12 multiline" >
                                <label class="field_title"></label>
                                <div class="form_input">

                                    <div class="form_grid_6 alpha">

                                        <?php echo $this->Form->text('direccion', array('placeholder' => 'Coloque la direccion', 'tabindex' => 4)) ?>
                                        <span class=" label_intro">Direcci&oacute;n</span>
                                    </div>
                                    <div class="form_grid_6 ">

                                        <?php echo $this->Form->text('telefono', array('placeholder' => 'Coloque el telefono', 'tabindex' => 4)) ?>
                                        <span class=" label_intro">Telefono</span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                                <div class="form_input">
                                    <div class="form_grid_6 alpha">
                                        <?php echo $this->Form->text('celular', array('placeholder' => 'Coloque el celular', 'class' => 'validate number', 'tabindex' => 4)) ?>

                                        <span class=" label_intro">Celular </span>
                                    </div>
                                    <div class="form_grid_6 ">
                                        <?php //echo $this->Form->text('correo', array('placeholder' => 'Coloque el celular', 'tabindex'=>4)) ?>
                                        <?php echo $this->Form->email('correo', array('placeholder' => 'Coloque el correo', 'id' => 'email', 'tabindex' => 4)) ?>

                                        <span class=" label_intro">E-Mail</span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                                <div class="form_input">
                                    <div class="form_grid_4 alpha">
                                        <select id="dpto_1" data-placeholder="Seleccione la provincia..." class="chzn-select full" name="data[Paciente][departamento_id]" tabindex="4">
                                            <option value=""></option>
                                            <?php foreach ($departamentos as $departamento): ?>
                                                <?php if ($this->request->data['Paciente']['departamento_id'] == $departamento['Departamento']['id']): ?>

                                                    <option value="<?php echo $departamento['Departamento']['id'] ?>" selected="selected">
                                                        <?php echo $departamento['Departamento']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $departamento['Departamento']['id'] ?>">
                                                        <?php echo $departamento['Departamento']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>

                                            <?php endforeach; ?>
                                        </select>
                                        <span class=" label_intro">DEPARTAMENTO</span>
                                    </div>
                                    <div class="form_grid_4" id="carga_prov1">
                                        <select data-placeholder="Seleccione la provincia..." class="chzn-select full" name="data[Paciente][provincia_id]" tabindex="4">
                                            <option value=""></option>
                                             <?php foreach ($provincias as $provincia): ?>
                                                <?php if ($this->request->data['Paciente']['provincia_id'] == $provincia['Provincia']['id']): ?>
                                                    <option value="<?php echo $provincia['Provincia']['id'] ?>" selected="selected">
                                                        <?php echo $provincia['Provincia']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $provincia['Provincia']['id'] ?>">
                                                        <?php echo $provincia['Provincia']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </select>
                                        <span class=" label_intro">PROVINCIA</span>
                                    </div>

                                    <span class="clear"></span>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="form_grid_12">
                                <label class="field_title">Seguro asociado</label>
                                <div class="form_input">

                                    <?php if(!empty($this->request->data['PacientesSeguro'])):?>  
                                    <?php echo $this->Form->hidden('PacientesSeguro.id', array('value'=>$this->request->data['PacientesSeguro'][0]['id']))?>
                                    <?php endif;?>
                                    <?php echo $this->Form->hidden('PacientesSeguro.paciente_id', array('value'=>$this->request->data['Paciente']['id']))?>

                                    <div class="form_grid_4 alpha">
                                        <select data-placeholder="Seleccione un seguro..." class="chzn-select full" name="data[PacientesSeguro][seguro_id]" tabindex="5">
                                            <option value=""></option>
                                             <?php foreach ($seguros as $s): ?>
                                                <?php if ($this->request->data['PacientesSeguro'][0]['seguro_id'] == $s['Seguro']['id']): ?>
                                                    <option value="<?php echo $s['Seguro']['id'] ?>" selected="selected">
                                                        <?php echo $s['Seguro']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $s['Seguro']['id'] ?>">
                                                        <?php echo $s['Seguro']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </select>
                                        <span class=" label_intro">SEGURO</span>
                                    </div>
                                    <div class="form_grid_4" id="carga_prov1">
                                        <select data-placeholder="Seleccione el colegio..." class="chzn-select full" name="data[PacientesSeguro][colegio_id]" tabindex="4">
                                            <option value=""></option>
                                             <?php foreach ($colegios as $c): ?>
                                                <?php if ($this->request->data['PacientesSeguro'][0]['colegio_id'] == $c['Colegio']['id']): ?>
                                                    <option value="<?php echo $c['Colegio']['id'] ?>" selected="selected">
                                                        <?php echo $c['Colegio']['nombre'] ?>
                                                    </option>
                                                <?php else: ?>
                                                    <option value="<?php echo $c['Colegio']['id'] ?>">
                                                        <?php echo $c['Colegio']['nombre'] ?>
                                                    </option>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </select>
                                        <span class=" label_intro">COLEGIO,solo para seguro escolar</span>
                                    </div>
                                    <div class="form_grid_4">
                                        <?php echo $this->Form->text('PacientesSeguro.curso', array('placeholder'=>'Solo para colegios', 'tabindex' => 5, 'value'=>$this->request->data['PacientesSeguro'][0]['curso'])) ?>
                                        <span class=" label_intro">CURSO</span>
                                    </div>
                                    <div class="form_grid_4">
                                        <?php echo $this->Form->textarea('PacientesSeguro.observaciones', array('tabindex' => 1)) ?>
                                        <span class=" label_intro">OBSERVACIONES</span>
                                    </div>
                                    <span class="clear"></span>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="form_grid_12">
                                <div class="form_input">
                                    <td>
                                        <button type="submit" class="btn_small btn_blue"><span>Guardar cambios</span></button>
                                        <button type="reset" class="btn_small btn_orange"><span>Limpiar datos</span></button>
                                    </td>
                                    <td>
                                        <p>&nbsp;</p>
                                        <?php $ruta = $this->request->data['Paciente']['foto'];?>
                                        <?php echo $this->Html->image("$ruta", array('width'=>200, 'height'=>180))?>
                                        <div class="btn_30_orange">
                                             <a href="<?php echo $this->Html->url(array('action' => 'editarfoto', $this->request->data['Paciente']['id'] )) ?>" title="Editar foto"><span class="icon back"></span><span class="btn_link">NUEVA FOTO</span></a>
                                        </div>
                                    </td>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
            </form>
        </div>
        <script>
            $(document).ready(function() {
                $('#departamento').hide();
                $('#provincia').hide();

                if ($('#lugar1').is(':checked')) {
                    $('#departamento').hide();
                    $('#provincia').show('slow');
                    //$('#carga_prov1').load('<?php echo $this->Html->url(array('action' => 'ajaxprovincia')) ?>/' + this.value);
                } else {
                    $('#provincia').hide();
                    $('#departamento').show('slow');
                }

                $('#cb_dpto').change(function() {
                    if ($('#lugar1').is(':checked')) {
                        console.log('selecciono provincia');
                        $('#cb_provincia').load('<?php echo $this->Html->url(array('action' => 'ajaxprovinciap')) ?>/' + this.value);
                    } else {
                        console.log('selecciono ciudad');
                        $('#cb_provincia').load('<?php echo $this->Html->url(array('action' => 'ajaxprovincia')) ?>/' + this.value);
                    }
                });
                $('#dpto_1').change(function() {
                    if ($('#lugar2').is(':checked')) {
                        console.log('selecciono ciudad');
                        $('#carga_prov1').load('<?php echo $this->Html->url(array('action' => 'ajaxprovincia')) ?>/' + this.value);
                    } else {
                        console.log('selecciono provincia');
                        $('#carga_prov1').load('<?php echo $this->Html->url(array('action' => 'ajaxprovinciap')) ?>/' + this.value);
                    }


                });

                $('#lugar1').click(function() {
                    $('#departamento').hide();
                    $('#provincia').show('slow');

                    //$('#provincia').toggle('slow');
                });
                $('#lugar2').click(function() {
                    $('#provincia').hide();
                    $('#departamento').show('slow');

                    //$('#departamento').toggle('slow');
                });
            });
        </script>

    </div>
    <span class="clear"></span>
</div>
